<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下载列表</title>
    <style>
        /* CSS样式部分，和原代码中的<style scoped>内容基本一致，去除了scoped属性 */
        .download-container {
            padding: 20px;
        }

        .category-title {
            font-size: 1.5em;
            color: #333;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 2px solid #4a90e2;
        }

        .download-list {
            display: flex;
            flex-direction: row;
            gap: 20px;
            margin-top: 20px;
            align-items: center;
            justify-items: start;
            flex-wrap: wrap;
        }

        .download-item {
            width: 100%;
            width: 30%;
        }

        .download-item h3 {
            margin: 0 0 10px 0;
            color: #2c3e50;
        }

        .download-links {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .download-links a {
            color: #4a90e2;
            text-decoration: none;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            max-width: 100%;
        }

        .description-link {
            font-weight: bold;
        }

        .url-link {
            color: #666;
            font-size: 0.9em;
        }

        .download-links a:hover {
            text-decoration: underline;
        }

        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 20px;
            gap: 20px;
        }

        .page-btn {
            padding: 8px 16px;
            border: 1px solid #4a90e2;
            background-color: white;
            color: #4a90e2;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.3s;
        }

        .page-btn:hover:not(:disabled) {
            background-color: #4a90e2;
            color: white;
        }

        .page-btn:disabled {
            border-color: #ccc;
            color: #ccc;
            cursor: not-allowed;
        }

        .page-info {
            font-size: 1.1em;
            color: #666;
        }
    </style>
</head>

<body>
<div class="download-container">
    <h2>下载列表</h2>
    <div class="download-list">
        <!-- 这里通过JavaScript动态生成下载项内容 -->
    </div>
    <!-- 分页控件 -->
    <div class="pagination">
        <button class="page-btn" id="prevBtn">上一页</button>
        <span class="page-info" id="pageInfo"></span>
        <button class="page-btn" id="nextBtn">下一页</button>
    </div>
</div>

<script>
    // 定义下载项数据结构，和原Vue代码中的接口定义对应
    function DownloadItem(id, name, description, url) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.url = url;
    }

    // 原始下载项数据数组，和原Vue代码中的downloadItems数组内容一致
    const downloadItems = [
        new DownloadItem(1, 'redis桌面管理工具', 'Another Redis Desktop Manager.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/Another%20Redis%20Desktop%20Manager.exe'),
        new DownloadItem(2, 'APIfox', 'Apifox客户端 64位_2.5.4.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/Apifox%E5%AE%A2%E6%88%B7%E7%AB%AF%2064%E4%BD%8D_2.5.4.exe'),
        new DownloadItem(3, '热键', 'AutoHotkey_2.0.18_setup.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/AutoHotkey_2.0.18_setup.exe'),
        new DownloadItem(4, 'Cursor编辑器', 'Cursor Setup 0.42.4 - x64.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/Cursor%20Setup%200.42.4%20-%20x64.exe'),
        new DownloadItem(5, 'Docker Desktop', 'Docker Desktop Installer.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/Docker%20Desktop%20Installer.exe'),
        new DownloadItem(6, '飞书', 'Feishu-win32_ia32-7.32.8-signed.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/Feishu-win32_ia32-7.32.8-signed.exe'),
        new DownloadItem(7, 'SSH工具', 'MobaXterm_Installer_v24.1.zip', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/MobaXterm_Installer_v24.1.zip'),
        new DownloadItem(8, '截图工具(钉图)', 'Snipaste截图工具.zip', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/Snipaste%E6%88%AA%E5%9B%BE%E5%B7%A5%E5%85%B7.zip'),
        new DownloadItem(9, '远程工具', 'ToDesk_Setup.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/ToDesk_Setup.exe'),
        new DownloadItem(10, 'VsCode编辑器', 'VSCodeUserSetup-x64-1.91.1.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/VSCodeUserSetup-x64-1.91.1.exe'),
        new DownloadItem(11, 'Visual Studio 编辑器', 'VisualStudioSetup.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/VisualStudioSetup.exe'),
        new DownloadItem(12, 'Zoom放大画笔工具', 'ZoomIt画笔工具.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/ZoomIt%E7%94%BB%E7%AC%94%E5%B7%A5%E5%85%B7.exe'),
        new DownloadItem(13, '数据库管理工具(datagrip)', 'datagrip-2023.3.3.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/datagrip-2023.3.3.exe'),
        new DownloadItem(14, 'idea编辑器2031.3.3', 'ideaIU-2021.3.3.win.zip', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/ideaIU-2021.3.3.win.zip'),
        new DownloadItem(15, 'idea编辑器2024.1.4', 'ideaIU-2024.1.4.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/ideaIU-2024.1.4.exe'),
        new DownloadItem(16, 'java环境(JDK11)', 'jdk-11.0.18_windows-x64_bin.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/jdk-11.0.18_windows-x64_bin.exe'),
        new DownloadItem(17, 'java环境(JDK8)', 'jdk-8u361-windows-x64.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/jdk-8u361-windows-x64.exe'),
        new DownloadItem(18, 'java环境(JDK17)', 'zulu17.54.21-ca-jdk17.0.13-win_x64.msi', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/zulu17.54.21-ca-jdk17.0.13-win_x64.msi'),
        new DownloadItem(19, 'java环境(JDK21)', 'zulu21.36.17-ca-jdk21.0.4-win_x64.msi', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/zulu21.36.17-ca-jdk21.0.4-win_x64.msi'),
        new DownloadItem(20, 'mysql8.0', 'mysql-installer-community-8.0.26.0.msi', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/mysql-installer-community-8.0.26.0.msi'),
        new DownloadItem(21, '数据库管理工具(navicat)', 'navicat162_sqlserver_cs_x64.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/navicat162_sqlserver_cs_x64.exe'),
        new DownloadItem(22, 'windows桌面快捷方式管理工具', 'nexus.zip', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/nexus.zip'),
        new DownloadItem(23, 'Nodejs', 'node22.0.msi', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/node22.0.msi'),
        new DownloadItem(24, '小皮', 'phpstudy_x64_8.1.1.3.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/phpstudy_x64_8.1.1.3.exe'),
        new DownloadItem(25, 'python编译器', 'pycharm-professional-2024.1.1.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/pycharm-professional-2024.1.1.exe'),
        new DownloadItem(26, 'python环境(3.12)', 'python-3.12.3-amd64.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/python-3.12.3-amd64.exe'),
        new DownloadItem(27, 'Markdown编辑器', 'typora-setup-x64（中文版）.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/typora-setup-x64%EF%BC%88%E4%B8%AD%E6%96%87%E7%89%88%EF%BC%89.exe'),
        new DownloadItem(28, '前端', 'webstorm.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/webstorm.exe'),
        new DownloadItem(29, '思维导图工具', 'xmind8思维导图工具.exe', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/xmind8%E6%80%9D%E7%BB%B4%E5%AF%BC%E5%9B%BE%E5%B7%A5%E5%85%B7.exe'),
        new DownloadItem(30, 'Xpath浏览器插件', 'xpath_helper-master.zip', 'https://downloaddemo.oss-cn-beijing.aliyuncs.com/xpath_helper-master.zip'),
        new DownloadItem(31,"中间间elasticSearch","elasticsearch-8.17.2-windows-x86_64.zip","https://downloaddemo.oss-cn-beijing.aliyuncs.com/elasticsearch-8.17.2-windows-x86_64.zip"),
        new DownloadItem(32,"Ai盒子","Chatbox-1.9.7-Setup.exe","https://downloaddemo.oss-cn-beijing.aliyuncs.com/Chatbox-1.9.7-Setup.exe"),
        new DownloadItem(33,"火狐快捷","Firefox_95.0.2_Portable.7z","https://downloaddemo.oss-cn-beijing.aliyuncs.com/Firefox_95.0.2_Portable.7z"),
        new DownloadItem(34,"maven包依赖管理工具","apache-maven-3.5.3.zip","https://downloaddemo.oss-cn-beijing.aliyuncs.com/apache-maven-3.5.3.zip"),
        new DownloadItem(35,"命令行","ffmpeg.zip","https://downloaddemo.oss-cn-beijing.aliyuncs.com/ffmpeg.zip")
    ];

    const itemsPerPage = 12;
    let currentPage = 1;

    // 计算总页数的函数，和原Vue代码中的computed计算属性类似
    function calculateTotalPages() {
        return Math.ceil(downloadItems.length / itemsPerPage);
    }

    // 获取当前页数据的函数，类似原Vue代码中的分页数据计算逻辑
    function getPaginatedItems() {
        const start = (currentPage - 1) * itemsPerPage;
        const end = start + itemsPerPage;
        return downloadItems.slice(start, end);
    }

    // 生成下载项HTML元素并添加到页面的函数
    function renderDownloadItems() {
        const downloadList = document.querySelector('.download-list');
        downloadList.innerHTML = '';
        const paginatedItems = getPaginatedItems();
        paginatedItems.forEach(item => {
            const downloadItemDiv = document.createElement('div');
            downloadItemDiv.classList.add('download-item');
            downloadItemDiv.innerHTML = `
                    <h3>${item.name}</h3>
                    <div class="download-links">
                        <a href="${item.url}" target="_blank" class="description-link">${item.description}</a>
                        <a href="${item.url}" target="_blank" class="url-link" title="${item.url}">${truncateUrl(item.url)}</a>
                    </div>
                `;
            downloadList.appendChild(downloadItemDiv);
        });
    }

    // 截断URL显示的函数，和原Vue代码中的truncateUrl函数一致
    function truncateUrl(url) {
        return url.length > 100? url.substring(0, 100) + '...' : url;
    }

    // 更新分页信息显示的函数
    function updatePageInfo() {
        const totalPages = calculateTotalPages();
        const pageInfoSpan = document.getElementById('pageInfo');
        pageInfoSpan.textContent = `${currentPage} / ${totalPages}`;
        const prevBtn = document.getElementById('prevBtn');
        const nextBtn = document.getElementById('nextBtn');
        prevBtn.disabled = currentPage === 1;
        nextBtn.disabled = currentPage === totalPages;
    }

    // 初始化页面，渲染下载项和分页信息
    function init() {
        renderDownloadItems();
        updatePageInfo();
        const prevBtn = document.getElementById('prevBtn');
        const nextBtn = document.getElementById('nextBtn');
        prevBtn.addEventListener('click', () => {
            if (currentPage > 1) {
                currentPage--;
                renderDownloadItems();
                updatePageInfo();
            }
        });
        nextBtn.addEventListener('click', () => {
            const totalPages = calculateTotalPages();
            if (currentPage < totalPages) {
                currentPage++;
                renderDownloadItems();
                updatePageInfo();
            }
        });
    }

    window.onload = init;
</script>
</body>

</html>